// 滚动出现
$(window).scroll(function () {
    if ($(document).scrollTop() >= 400) {
        $(".back").stop().fadeIn()
    } else {
        $(".back").stop().fadeOut()
    }
})
// 返回顶部
$(".back").click(function () {
    // $(document).animater()是不对的 animater只对元素有效
    $("body,html").stop().animate({
        scrollTop: 0
    })
})
// 电梯导航
var report = $(".banner .b-bot").offset().top;
toggleTool()
function toggleTool() {
    if ($(document).scrollTop() >= report) {
        $(".fixedtool").fadeIn();
    } else {
        $(".fixedtool").fadeOut();
    }
}
// 节流阀
var flag = true;
$(window).scroll(function () {
    toggleTool()
    if (flag) {
        $(".content .f").each(function (i, ele) {
            if ($(document).scrollTop()>=$(ele).offset().top) {
                $(".fixedtool li").eq(i).addClass("active").siblings().removeClass("active")
            }
        })
    }
    
})
$(".fixedtool li").click(function () {
    flag = false;
    $(this).addClass("active").siblings().removeClass("active")
    // console.log($(this).index());
    var scrollTops = $(".content .f").eq($(this).index()).offset().top;
    $("body,html").stop().animate({
        scrollTop: scrollTops
    }, function () {
        flag=true
    })
})
// 热门试用
var uls = document.querySelector(".bot-ul")
var xml = new XMLHttpRequest();
xml.open("get", "./json/04-data.json", true);
xml.onreadystatechange = function () {
    if (xml.readyState == 4 && xml.status == 200) {
        var sp = JSON.parse(xml.responseText);
        // console.log(sp);
        for (var i = 0; i < sp.length; i++) {
            // console.log(sp[i]);
            uls.innerHTML += `<li>
                        <img src=${sp[i].img} alt="">
                        <h4>${sp[i].title}</h4>
                        <span>${sp[i].year}</span>
                        <span>${sp[i].sum}</span>
                        <p><b>1392</b>申请</p>
                        <p>${sp[i].endDate}</p>
                        </li>`
        }

    }
}
xml.send();

// 报告精品
$.ajax({
    url: "http://127.0.0.1:3000/report/new",
    type: "get",
    success: function (res) {
        for (var i = 0; i < res.length - 4; i++) {
            $(".report .content ul").append(`
            <li>
            <img src=${res[i].img} alt="">
            <p>${res[i].text}</p>
            <div class="liuliang">
                <div class="name">
                    <span></span>
                    ${res[i].uName}
                </div>
                <div class="dianzan">
                    <span>
                        <img src="./img/css/img/zan.png" alt="">
                        ${res[i].num}
                    </span>
                    <span>
                        <img src="./img/css/img/reply.png" alt="">
                        ${res[i].apply}
                    </span>
                </div>
            </div>
        </li>
            `)
        }
    }
})

// 导购精品
$.ajax({
    url: "http://127.0.0.1:3000/report/new",
    type: "get",
    success: function (res) {
        for (var i = 8; i < res.length; i++) {
            $(".guid .content ul").append(`
            <li>
            <img src=${res[i].img} alt="">
            <p>${res[i].text}</p>
            <div class="liuliang">
                <div class="name">
                    <span></span>
                    ${res[i].uName}
                </div>
                <div class="dianzan">
                    <span>
                        <img src="./img/css/img/xin.png" alt="">
                        ${res[i].num}
                    </span>
                    <span>
                        <img src="./img/css/img/reply.png" alt="">
                        ${res[i].apply}
                    </span>
                </div>
            </div>
        </li>
            `)
        }

    }
})

// 发现酷玩
$.ajax({
    url: "http://127.0.0.1:3000/play/new",
    type: "get",
    success: function (res) {
        for (var j = 0; j < res.length; j++) {
            var newArray = res[j]
            for (var i = 0; i < newArray.length; i++) {
                $(".play .content ul").append(`
                <li>
                            <img src=${newArray[i].img} alt="">
                            <h4>${newArray[i].text}</h4>
                            <p>${newArray[i].description}</p>
                            <div class="liuliang">
                                <div class="name">
                                    ${newArray[i].price}
                                </div>
                                <div class="dianzan">
                                    <span>
                                        <img src="./img/css/img/xin.png" alt="">
                                        ${newArray[i].like}
                                    </span>
                                    <span>
                                        <img src="./img/css/img/reply.png" alt="">
                                        ${newArray[i].words}
                                    </span>
                                </div>
                            </div>
                </li>`)
            }
        }
    }
})
// 加载更多
$(".mores").on("click", function () {
    console.log(1);
    $(".c-play").css("height", "1300px")
    $(this).html("没有更多了~").css("color", "#333")
})